package com.demo.alarm;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class AlarmAgent {

	public void init() {
		Thread connection = new Thread(new ConnectingTask());
		connection.start();
		ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor(5, new ThreadFactory() {

			private final AtomicInteger index = new AtomicInteger();

			@Override
			public Thread newThread(Runnable r) {
				Thread thread = new Thread();
				thread.setName("heartbeat-thread-" + index);
				thread.setDaemon(true);
				return thread;
			}
		});

		heartbeatExecutor.scheduleAtFixedRate(new HeartBeatTask(), 5, 2, TimeUnit.SECONDS);
	}
}
